package org.example.springboot.springboot3002aop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * @author 莫磊
 * @date 2025/8/16
 * @description
 */
@Slf4j
@Aspect
@Component
public class LogAspect {

    @Pointcut("execution(* org.example..service..*(..))")
    public void serviceModule() {}


    @Before("serviceModule()")
    public void logBefore(JoinPoint joinPoint) {

        log.info("执行方法：{}#{}的前置处理", joinPoint.getTarget().getClass().getSimpleName(), joinPoint.getSignature().getName());
    }

    @AfterReturning("serviceModule()")
    public void logAfterReturning(JoinPoint joinPoint) {
        log.info("执行方法：{}#{}的后置处理", joinPoint.getTarget().getClass().getSimpleName(), joinPoint.getSignature().getName());
    }
}
